window.baseUrl = "http://localhost:8080/ForWhatSite"
window.webUrl = "http://localhost:63343/ForWhatSite"

async function ajax(method, secondUrl, postParam, okCallBack, failCallBack) {
    return axios({
            url: window.baseUrl + secondUrl,
            method: method,
            data: postParam,
            withCredentials: true,
            header: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }
    ).then(res => {
            if (okCallBack != null) {
                return okCallBack(res.data)
            }
        }
    ).catch(err => {
        if (failCallBack != null) {
            failCallBack(res.data)
        }
    })

    //
    // let xhr = new XMLHttpRequest()
    // xhr.onreadystatechange = function () {
    //     if (this.readyState == 4) {
    //         if (this.status == 200) {
    //             let json = JSON.parse(this.responseText)
    //             okCallBack(json)
    //         } else {
    //             if (failCallBack != null) {
    //                 failCallBack()
    //             }
    //             // alert("连接服务器失败!")
    //
    //         }
    //     }
    // }
    //
    // if (async == undefined) {
    //     async = true
    // }
    // xhr.open(method, window.baseUrl + secondUrl, async)
    //
    //
    // xhr.withCredentials = true;
    //
    // if (typeof (postParam) != string) {
    //     xhr.send()
    // } else {
    //     xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
    //     console.log(JSON.stringify(postParam));
    //     xhr.send()
    // }
    //

}

function goto(url) {
    window.location.href = window.webUrl + url
}

function gotoIndex() {
    goto("/index.html")
}


//时间戳转换方法    date:时间戳数字
function formatDate(date) {
    var date = new Date(date);
    var YY = date.getFullYear() + '-';
    var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
    var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return YY + MM + DD + " " + hh + mm + ss;
}